let timerId: NodeJS.Timer | null;

export default (fn: any, delay: number): any => {
  return (...args: any): void => {
    if (timerId) {
      clearTimeout(timerId);
      timerId = null;
    }
    timerId = setTimeout((): void => {
      fn(...args);
    }, delay);
  };
};
